// components/searchBar/searchBar.js
Component({
  /**
   * 组件的属性列表
   */
  properties: {
    disabled: {
      type: Boolean,
      value: false
    },
    placeholder: {
      type: String,
      value: "请输入搜索关键词"
    },
    showRight: {
      type: Boolean,
      value: false
    },
    words: {
      type: String,
      value: ""
    },
    showShare: {
      type: Boolean,
      value: false,
    }
  },

  /**
   * 组件的初始数据
   */
  data: {
    searchWords: "",
    focusStatus: false,
  },
  observers: {
    'words': function (newValue) {
      this.setData({
        searchWords: newValue
      })
    }
  },
  lifetimes: {
    attached: function () {
      // 在组件实例进入页面节点树时执行
      if (this.properties.words) {
        this.setData({
          searchWords: this.properties.words
        })
      }
    },
    detached: function () {

    },
  },

  /**
   * 组件的方法列表
   */
  methods: {

    //搜索聚焦
    searchBarFocus() {
      console.log("JJLog:搜索框聚焦了:=====:");
    },
    //搜索改变
    searchBarChange(e) {
      // console.log("JJLog:搜索词:" + JSON.stringify(e));
      let searchWords = e.detail;
      this.setData({
        searchWords: e.detail
      })
      // this.triggerEvent('searchAction', { searchWord: searchWords });
    },
    startSearchAction() {
      this.triggerEvent('searchAction', { searchWord: this.data.searchWords });
    },
    //搜索失去焦点
    searchBlur() {

    },
    //禁用后跳转页面:
    pushPage() {
      if (this.properties.disabled) {
        console.log("JJLog:跳转页面嘛...");
        wx.navigateTo({
          url: '/firstPackage/pages/searchPage/searchPage',
        })
      }

    },
    //右边跳转:
    rightPushPage() {
      wx.navigateTo({
        url: '/firstPackage/pages/mapSearch/mapSearch',
      })
    },

  }
})
